home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / print.txt < prev    next >
Text File  |  1994-11-08  |  13KB  |  314 lines

  1. /*
  2. █████████████████████████████████████████████████████████████████████████████
  3. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ KNOW-HOW.PRINT ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  6. █████████████████████████████████████████████████████████████████████████████
  7.  
  8. This text contain complete description of KNOW_HOW.PRINT 5.0x, the
  9. product in the 5th version of library. It provide the following features:
  10.     a) Creation of the graphics "page" of any size on hard disk.
  11.     b) Data exchange between screen, "page" and PCX file. Color <---> B&W PCX
  12.        conversion.
  13.     c) Scrolling of the "page" in clip area on screen with any deformation.
  14.     d) Direct drawing on the "page" (pixel-by-pixel).
  15.     e) Print on EPSON or LJ-compatible printers with any deformation.
  16.     f) Cut and paste operations with images.
  17.  
  18. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  19. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ FILES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  20. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  21.  
  22. ▐▐▐▐▐▐▐ Files GLOBAL, COLOR and so on - see description of KNOW-HOW.INTERFACE
  23. ▐▐▐▐▐▐▐ Files PIXEL.H and PIXEL.CPP defines array of patterns for COLOR to
  24.     B&W conversion and so on:
  25. extern char pattern[][8];
  26.     The put_pixel() functions works as pattern and random brushes.
  27. extern void put_pixel(int x, int y, int pat, int bak = global_i[7],
  28.     int attr = global_i[6]);
  29. extern void put_pixel_error_prop(int x, int y, int weight, int pat,
  30.     int bak = global_i[7], int attr = global_i[6]);
  31.     Put your attention to the usage of global_i[6 and 7] elements (see
  32.     description of KNOW-HOW.INTERFACE).
  33.  
  34. ▐▐▐▐▐▐▐ File PATTERNS.CPP assign patterns (8x8). User could add his own
  35.     patterns.
  36. ▐▐▐▐▐▐▐ File IMAGE_P.H and define image as a structure:
  37.  
  38. struct imageType
  39.     {
  40.     int xmax, ymax;
  41.     unsigned char data[];
  42.     };
  43. typedef imageType* imageP;
  44.       Now we could trace this objects of structure, change fields of structure
  45.     and so on.
  46.  
  47. ▐▐▐▐▐▐▐ Files IMAGEBUF.H and IMAGEBUF.CPP are usefull for COLOR->B&W
  48.     conversions.
  49.     The b&w() function returns BW pixel, BLACK of WHITE (1), depending on
  50.     pattern for color. Defined in GBUF.H
  51. extern bw_pix(int color, int x, int y);
  52.        The ImageBuffer structure is used for realization of get_pixel() for
  53.        image (not screen).
  54. struct ImageBuffer
  55.     {
  56.     uchar pixels[8];
  57.     loc coord;
  58.     ImageBuffer() { coord.Y = -1; }
  59.     uchar image_get_pixel(imageP image, int byte, int vert_shift);
  60.     };
  61.  
  62. ▐▐▐▐▐▐▐ Files IMAGE.H and IMAGE.CPP contains the simple toolkit for working
  63.     with images. Images are in the (Borland) getimage() formate. We use
  64.     the postulate, that color pictures have 4 planes, and BW pictures -
  65.     one.
  66.  
  67. enum { BW, COLOR }; Enumeration define image type: 16 color or monochrome.
  68.  
  69.     Read pixel color from image.
  70. extern int image_get_pixel(imageP image, loc pos, int bitpx = 1,
  71.                int nplanes = 4);
  72.     Put pixel to the image, changing all planes, if necessary.
  73. extern void image_put_pixel(imageP image, loc pos, int col,
  74.                 int bitpx = 1, int nplanes = 4);
  75.  
  76.     Shows part of image on screen with deformation.
  77.     Arguments: src - rectangle in source image, dest- left-top coordinates
  78.            on screen, ... , comp_s and comp_d - deformation of source
  79.            and destination, it corresponds to divx, divy, multx, multy,
  80.            flag == 1 - use image_get_pixel - for pixel - to - pixel
  81.            (not byte - to byte) output, trans contains directive to
  82.            use one of the colors as transparent (do not show it).
  83.            Default value is 16 (no transparent color).
  84. extern void image_screen(imageP image, rect src, loc dest, int bitpx = 1,
  85.          int nplanes = 4, loc comp_s = loc(1, 1),
  86.          loc comp_d = loc(1, 1), int flag = 0);
  87.  
  88.     Copies part of screen to the part of image, no deformation.
  89. extern void screen_image(imageP image, rect scr, loc dest);
  90.  
  91. ▐▐▐▐▐▐▐ Files PCXSTRM.H and PCXSTRM.CPP work with PCX file as with stream,
  92.     to speed up the calculations.
  93.  
  94. ▐▐▐▐▐▐▐ Files PCX.H and PCX.CPP work with screen output of PCX. It define
  95.     PCX file header as:
  96.  
  97. struct pcxheader {
  98.      char       manuf;           // Always = 10 for Paintbrush
  99.      char       hard;            // Version info
  100.      char       encod;           // Coding ( = 1)
  101.      char       bitpx;           // bit per pixel
  102.      int        x1;              // Picture size (inclusive)
  103.      int        y1;
  104.      int        x2;
  105.      int        y2;
  106.      int        hres;            // horiz. resolution of display
  107.      int        vres;            // vert. resolution of display
  108.      char       clrma[48];       // Palette
  109.      char       vmode;           // Ignored
  110.      char       nplanes;         // Num. of planes (rel. 2.5 = 0)
  111.      int        bplin;           // Bytes per line
  112.      int        palinfo;         // Palette info (1=col.,2 = grey)
  113.      int        shres;           // Scanner resolution
  114.      int        svres;           //
  115.      char       xtra[54];        // Filter
  116.  };
  117.     and some functions for manipulations with file in PCX formate:
  118.  
  119. void put_pcx_header(FILE* f, pcxheader* p, loc pos, int pal = 1,
  120.     int planes = N_PLANES);
  121. int get_pcx_header(pcxstream* s, pcxheader* p_h);
  122. int get_pcx_header(FILE* file, pcxheader* p_h);
  123. int get_pcx_header(char* name, pcxheader* p_h);
  124.  
  125.     The "pal" flag below could be set to 0 for speed, but resulting
  126.     files will be compatible only with KNOW-HOW functions.
  127.     Always 1 bit / pixel and 4 planes 16-color images
  128. void pcx_scr_file(rect coord, char* name, int pal = 0);
  129. int pcx_file_scr(char* name, loc pos, int* cells = NULL, int mode = COPY_PUT);
  130.  
  131. ▐▐▐▐▐▐▐ Files IC_PART.H and IC_PART.CPP contains cut-and-paste functions.
  132. ▐▐▐▐▐▐▐ Files B&W.H and B&W.CPP process COLOR <----> B&W PCX convertion.
  133.  
  134. int pcx_bw_to_col(char* src_name, char* dest_name);
  135. int pcx_col_to_bw(char* src_name, char* dest_name);
  136.  
  137. ▐▐▐▐▐▐▐ Files MOVE.H and MOVE.CPP scroll the image.
  138. ▐▐▐▐▐▐▐ Files GBUF.H and GBUF.CPP realize graphical "page" on the disk.
  139.     Graphics buffer is a file, which consists of the number of "bounds".
  140.     Each "bound" is a part of virtual graphics page, with the same width,
  141.     and relatively low height. We can load "bound" with given number to
  142.     memory, change it, show it on screen, swap to disk buffer. Format of
  143.     bound is the same as in image (int, int, bitmap).
  144.     Do not use buffer < than screen.
  145.  
  146.    If you do not use interface library of KNOW-HOW, some files are
  147.        not necessary, as event.lib, and other. It is possible to exclude
  148.        them from project. In this case you should edit colors.cpp file,
  149.        and remove some functions: pColorSet, init_Know_How and so on.
  150.        You need only pScreenSet structure, declared in colors.h.
  151.  
  152. #define BOUND_SIZE 12500/2     // size of bound, bytes
  153.  
  154. enum { LEFT, UP, RIGHT, DN };  // Scroll directions
  155. BGI function is not correct, so we need:
  156. extern int image_size(int width, int heigth, int bitpx, int nplanes);
  157.  
  158. class GrafBuffer
  159.     {
  160.     public:
  161.     int loaded;            // is the buffer ready?
  162.     loc buf_dim;           // buffer dimentions, pixels
  163.     loc bound_size;        // dimentions of bounds, bound_size.X == buf_dim.X
  164.     rect screen_area;      // screen work area (l, t, r, b)
  165.     rect screen_position;  // position of screen in buffer
  166.     FILE* buffer;          // swap file
  167.     char* file_name;       // swap file
  168.     imageP image;          // image for bound
  169.     int nplanes;           // number of planes
  170.     int bitpx;             // bit per pixel in plane
  171.     int change_palette;    // use or not the palette when loading or saving PCX
  172.     int transparent;       // What color show as transparent
  173.     int mode;              // COPY_PUT ...
  174.     public:
  175.     GrafBuffer(loc dim, char* swapName,
  176.            rect screen_area = rect(0, 0, getmaxx(), getmaxy()),
  177.            int bpx = 1, int np = 4);
  178.     ~GrafBuffer() { fclose(buffer); delete image; unlink(file_name);
  179.             delete file_name; }
  180.  
  181.     long imagesize(); // if image > 64K, BGI function returns error
  182.     int imagesize(int x, int y);
  183.  
  184.     void set_screen_area(rect a) { screen_area = a; }
  185.     void set_screen_position(rect a) { screen_position = a; }
  186.     int b_open();     // open swap file (created by constructor)
  187.     void b_close();    // close swap file
  188.  
  189.     void clear();      // fills buffer file with '0'
  190.     loc get_dim() { return buf_dim; }
  191.     rect get_screen_pos() { return screen_position; }
  192.  
  193.     void set_mode(int m) { mode = m; }
  194.     void set_trans(int t) { transparent = t; }
  195.  
  196.     imageP get_bound(int number);
  197.     void put_bound(int number);
  198.     void get_BW(int number);  // get bound and keep it as BW
  199.  
  200.     void bound_screen(int number,      // put image from bound to screen src - in image, dest - on screen
  201.          loc comp_s = loc(1, 1),   // divx, divy, multx, multy
  202.          loc comp_d = loc(1, 1));  // rects are the outlines
  203.  
  204.     void screen_bound(int number);  // load bound from disk to memory, update from screen, put back
  205.  
  206.     void screen_buffer();       // swap screen to buffer
  207.     void buffer_screen(loc comp_s = loc(1, 1),   // from buffer to screen
  208.                loc comp_d = loc(1, 1));
  209.     void buffer_screen(rect temp,
  210.                loc comp_s = loc(1, 1),   // from buffer to screen
  211.                loc comp_d = loc(1, 1));
  212.  
  213.  
  214.     void buffer_disk(rect src, char* name);   // cut and paste
  215.  
  216.     void scroll(int shift, int direction, int show = 1);    // scrolling
  217.  
  218.     void pcx_buffer_file(rect src, char* name); // From buf to file
  219.     friend int pcx_file_buffer(GrafBuffer* buf, loc pos, char* name,
  220.                    int col = 16);
  221.  
  222. // Virtual BGI support
  223.     friend void dither_BW(int** threshold, rect coord, loc dim,
  224.               GrafBuffer* buf);
  225.     friend void bar(GrafBuffer* buf, rect coord);    // bar in buffer
  226.     };
  227.  
  228. ▐▐▐▐▐▐▐ Files PRINT.H and PRINT.CPP contains printer support code. Attention!
  229.     WINDOWS use files with the same name: PRINT.H.
  230.     PrintManager is the class, which may send buffer of GrafBuffer class
  231.     to printers of different types. The algorithm is: load "bound", print
  232.     it, load next...
  233.  
  234. #define MAXPAGE 2000    // maximum page width
  235.  
  236. enum { EPSON9 = 1, EPSON24, LASERJET_II };             // Printer type
  237. enum { DD, QD, LJ_100, LJ_150 };                       // Print density
  238. enum { PAPER_OFF = '8', PAPER_ON = '9' };              // Paper-end sensor
  239.  
  240. class PrintManager
  241.     {
  242.     protected:
  243.     int printer_type;      // see enum of printer types
  244.     int density;           // double or quadruple
  245.     int pass;              // how much time to repeate each pass
  246.     int mx, my, dx, dy;    // print time deformation
  247.     int left;              // left indent
  248.     int paper;             // paper-out sensor disable
  249.     int parity;            // minimal number of lines in bound (* 4 for color)
  250.     public:
  251.     PrintManager(int t, int d, int p = 1, rect cmp = rect(1, 1, 1, 1),
  252.         int lt = 0, int ppr = PAPER_ON, int pa = 1)
  253.         { printer_type = t; density = d; pass = p; mx = cmp.origin.X;
  254.           my = cmp.origin.Y; dx = cmp.corner.X; dy = cmp.corner.Y;
  255.           left = lt; paper = ppr; parity = pa; }
  256.  
  257.     void set_type(int t) { printer_type = t; }
  258.     void set_density(int d) { density = d; }
  259.     void set_pass(int p) { pass = p; }
  260.     void set_comp(int multx, int multy, int divx, int divy)
  261.         { mx = multx; my = multy; dx = divx; dy = divy; }
  262.     void set_left(int l) { left = l; }
  263.     void set_paper(int p) {paper = p; }
  264.  
  265.     void init_printer(int size, int sh);    // set current resolution and so on
  266.     void draw_string(char* str);            // draws graphic string
  267.     void draw_image(imageP image);          // print image
  268.     void draw_buffer(GrafBuffer* buf);      // prints buffer
  269.  
  270. If page if very big, we print it on few pages
  271.     void draw_pages(GrafBuffer* buf, char* work_name,
  272.             int maxpage = MAXPAGE);
  273. Print using page of maxpage width
  274.     void print_part(rect src, GrafBuffer* buf, char* work_name);
  275.     friend class GrafBuffer;
  276.     };
  277.  
  278. ..........................................................................
  279. Example:
  280. void main()
  281.     {
  282. Init Borland's graphics.
  283.     int gdriver = DETECT;
  284.     int gmode;
  285.     initgraph(&gdriver, &gmode, "");
  286. // Create Print manager and graphical buffer
  287.     PrintManager p(EPSON9, DD, 2, rect(1, 1, 1, 1), 0, PAPER_ON, 6);
  288.     GrafBuffer* g = new GrafBuffer(loc(750, 590), "work.buf",
  289.                    rect(0, 0, 500, getmaxy() - 1));
  290. // Create and clear page
  291.     g->b_open();
  292.     g->clear();
  293. // Load PCX file and show it
  294.     pcx_file_buffer(g, loc(0, 0), "about.pcy");
  295.     g->buffer_screen();
  296. // Print
  297.     p.draw_buffer(g);
  298.     p.draw_pages(g, "work1.buf", 320);
  299. // Deformation
  300.     p.set_comp(1, 2, 2, 1);
  301.     p.draw_buffer(g);
  302.  
  303.     p.set_comp(1, 1, 2, 2);
  304.     p.draw_buffer(g);
  305. // Print part of the image
  306.     p.print_part(rect(64, 50, 239, 200), g, "work1.buf");
  307.  
  308.     g->b_close();
  309.     delete g;
  310.     closegraph();
  311.     }
  312.  
  313.  
  314.